package com.parkreport.admin.city.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.common.pager.PageHelper;
import com.common.pager.PagerVO;
import com.common.util.StringUtil;
import com.parkreport.admin.areacity.service.AreaCityService;
import com.parkreport.admin.city.service.CityService;
import com.parkreport.base.BaseAction;
import com.parkreport.vo.CityVO;
import com.parkreport.vo.LareaVO;

public class CityAction extends BaseAction {
	private PagerVO pagerVO = null;
	private String ids = null;
	private String id="";
	
	private CityService service = new CityService();
	private List<CityVO> list = new ArrayList<CityVO>();
	private List<CityVO> cityList = new ArrayList<CityVO>();
	private List<LareaVO> arealist = new ArrayList<LareaVO>();
	private CityVO vo = new CityVO();
	private AreaCityService areaService = new AreaCityService();

	public String find(){
		log.info("==========find============");
	
		cityList = service.find();
		
		arealist =  areaService.find();
		return topager("/pages/admin/areacity/city_list.jsp");
		
	}
	
	public String edit(){
		log.info("==========edit============");
		if(!StringUtil.isBlank(id)){
			vo = service.get(id);
		}

		return topager("/pages/admin/areacity/edit.jsp");
		
	}
	public String saveList(){
		log.info("==========save============");
		String isSave = service.saveList(cityList);
		arealist =  areaService.find();
		this.getRequest().setAttribute("saveFlag", isSave);
		return redirect("/admin/City_find.action");
	}
	public String save(){
		log.info("==========save============");
		String isSave = service.save(vo);
		
		this.getRequest().setAttribute("saveFlag", isSave);
		return topager("/pages/admin/areacity/edit.jsp");
	}
	public void delete(){
		log.info("==========delete============"+ids);
		service.delete(ids);
		
	}

	public List<CityVO> getCityList() {
		return cityList;
	}

	public void setCityList(List<CityVO> cityList) {
		this.cityList = cityList;
	}

	public String getTree(){
		HttpServletResponse response = ServletActionContext.getResponse();
		String treeStr = areaService.getTree();
		
		log.info("treeStr==========="+treeStr);
		try {
			response.getWriter().write(treeStr);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return null;
	}
	
	//=========setter getter ===================
	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	public List<LareaVO> getArealist() {
		return arealist;
	}

	public void setArealist(List<LareaVO> arealist) {
		this.arealist = arealist;
	}

	public List<CityVO> getList() {
		return list;
	}

	public void setList(List<CityVO> list) {
		this.list = list;
	}

	public CityVO getVo() {
		return vo;
	}

	public void setVo(CityVO vo) {
		this.vo = vo;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public PagerVO getPagerVO() {
		return pagerVO;
	}

	public void setPagerVO(PagerVO pagerVO) {
		this.pagerVO = pagerVO;
	}

	
	
}
